/**
 * 
 */
package web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.IAlbum;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import session.UserContainer;

/**
 * @spring.bean name="muiscSearchStatusController"
 * @author isaac
 *
 */
public class MuiscSearchStatusController implements Controller {

	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession();
		UserContainer uc = (UserContainer)session.getAttribute(IConstants.Sessoin.USER_CONTAINER);
		
		Map<String, Object> beans = new HashMap<String, Object>();		
		
		if(uc.getMusic() != null) {
			Map<String, IAlbum> albumMap = new HashMap<String, IAlbum> (uc.getMusic().getAlbums());
			List<IAlbum> albums = new ArrayList<IAlbum>();
			for(String albumTitle: albumMap.keySet()) {
				albums.add(uc.getMusic().getAlbums().get(albumTitle));
			}
			
			beans.put("albums", albums);
			beans.put("albumCount", albums.size());
		}
		
		return new ModelAndView(IConstants.Views.MUSIC_SEARCH_STATUS, beans);
	}

}
